class RandomizedSet {
public:
    RandomizedSet() {
        srand((unsigned)time(NULL));
    }
    
    bool insert(int val) {
        if (mp.count(val)==1){
            return false;
        }
        num.push_back(val);
        mp.insert(make_pair(val,num.size()-1));
        return true;
    }
    
    bool remove(int val) {
        if (mp.count(val)==0){
            return false;
        }
        int index = mp[val];
        num[index] = num.back();//最后一个值
        //忘了这一句，千万不可忘记把最后一个移到前面需要改变mp
        mp[num.back()] = index;
        mp.erase(val);
        num.pop_back();
        return true;
    }
    
    int getRandom() {
        int randIndex = rand()%num.size();
        return num[randIndex];
    }
    private:
    vector<int> num;           //val append
    unordered_map<int,int> mp; //<val,index>
};

/**
 * Your RandomizedSet object will be instantiated and called as such:
 * RandomizedSet* obj = new RandomizedSet();
 * bool param_1 = obj->insert(val);
 * bool param_2 = obj->remove(val);
 * int param_3 = obj->getRandom();
 */